@import './variable.scss';
@import './base.scss';
@import './ch-icon.scss';
@import './markdown.scss';
@import './previewer.scss';
@import './print.scss';

@mixin cherryFont {
  font-family: $fontFamily;
  font-size: $fontSize;
}

// 主要布局控制，可以不合并进下面的区块
.cherry {
  display: flex;
  flex-flow: row wrap;
  align-items: stretch;
  align-content: flex-start;
  height: 100%;
  min-height: 100px;
  position: relative;
  // overflow: hidden;

  .cherry-editor,
  .cherry-previewer {
    max-height: calc(100% - #{$toolbarHeight});
    min-height: calc(100% - #{$toolbarHeight});
  }

  .CodeMirror {
    height: 100%;
  }

  &.cherry--no-toolbar {

    .cherry-toolbar,
    .cherry-sidebar {
      height: 0;
      display: none;
    }

    .cherry-editor,
    .cherry-previewer {
      max-height: 100%;
      min-height: 100%;
    }
  }

  div[data-type="codeBlock"]:hover  {
    position: relative;
    .cherry-code-preview-lang-select{
      display: block !important;
      position: absolute;
      transform: translate(2px, 50%);
    }

  }

  .cherry-preview--full {
    div[data-type="codeBlock"]:hover  {
      position: unset;
      .cherry-code-preview-lang-select{
        display: none !important;
        position: unset;
      }
    }
  }
}

.cherry {
  @include cherryFont;
  line-height: $lineHeight;
  color: $fontColor;
  background: $editorBg;
  box-shadow: $shadow;

  .ch-icon {
    vertical-align: middle;
  }

  .clearfix {
    zoom: 1;

    &:after {
      content: '.';
      display: block;
      height: 0;
      clear: both;
      visibility: hidden;
      overflow: hidden;
      font-size: 0;
    }
  }

  &.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99;
  }

  .no-select {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  .cherry-insert-table-menu {
    display: block;
    position: fixed;
    // z-index: 100;
    top: 40px;
    left: 40px;
    border-collapse: separate;
    box-shadow: $shadow;
    padding: 4px;
    border-radius: $borderRadius;
    width: auto;
    height: auto;

    &-item {
      padding: 7px;
      border: 1px solid $borderColor;

      &.active {
        background-color: $toolbarBtnBgHoverLight;
      }
    }
  }

  &[data-toolbar-theme='dark'] {
    .cherry-insert-table-menu-item {
      border-color: rgba(255, 255, 255, 0.2);

      &.active {
        background-color: $toolbarBtnColorDark;
      }
    }
  }
}

.cherry-dropdown {
  position: absolute;
  width: 130px;
  min-height: 40px;
  background: #fff;
  //border: 1px solid $borderColor;
  box-shadow: 0 5px 15px -5px rgba(0, 0, 0, 0.5);
  margin-left: -60px;
  z-index: 11;

  &-item {
    width: 100%;
    padding: 0 15px;
    text-align: left;
    display: inline-block;
    height: 36px;
    line-height: 36px;
    font-size: 14px;
    font-style: normal;
    cursor: pointer;
    box-sizing: border-box;

    &:hover {
      background: $toolbarBtnBgHoverLight;
      color: $toolbarBtnHoverColorLight;
    }

    .ch-icon {
      margin-right: 10px;
    }
  }

  [data-toolbar-theme='dark'] & {
    background: $toolbarBgDark;

    .cherry-dropdown-item {
      background: $toolbarBtnBgDark;
      color: $toolbarBtnColorDark;

      &:hover {
        background: $toolbarBtnBgHoverDark;
        color: $toolbarBtnHoverColorDark;
      }
    }
  }
}

.cherry-toolbar {
  position: relative;
  display: flex;
  // align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: $toolbarHeight;
  font-size: $toolbarFontSize;
  line-height: 2.8;
  flex-basis: 100%;
  box-sizing: border-box;
  z-index: 2;
  user-select: none;
  box-shadow: $toolbarShadowLight;
  background: $toolbarBgLight;
  overflow: hidden;

  [data-toolbar-theme='dark'] & {
    background: $toolbarBgDark;
    box-shadow: $toolbarShadowDark;

    .cherry-toolbar-button {
      color: $toolbarBtnColorDark;
      background: $toolbarBtnBgDark;

      &:hover {
        color: $toolbarBtnHoverColorDark;
        background: $toolbarBtnBgHoverDark;
      }
    }
  }

  .toolbar-left,
  .toolbar-right {
    display: flex;
    align-items: center;
    height: $toolbarHeight;
    overflow: hidden;
  }

  .toolbar-left {
    flex: 0 0 auto;
    margin-right: 20px;
  }

  .toolbar-right {
    flex: 0 1 auto;
    flex-direction: row-reverse;
    margin-left: 10px;
    box-sizing: border-box;
  }

  &.preview-only {
    .cherry-toolbar-button {
      display: none;
    }

    .cherry-toolbar-switchPreview {
      display: inline;
    }
  }

  &-button {
    float: left;
    padding: 0 12px;
    // margin: 4px 0;
    height: 38px;
    color: $toolbarBtnColorLight;
    background: transparent;
    border: 1px solid transparent;
    -webkit-transition: background-color ease-in-out 0.15s, color ease-in-out 0.15s, border-color ease-in-out 0.15s;
    transition: background-color ease-in-out 0.15s, color ease-in-out 0.15s, border-color ease-in-out 0.15s;
    cursor: pointer;
    font-style: normal;

    &:hover {
      color: $toolbarBtnHoverColorLight;
      background: $toolbarBtnBgHoverLight;
    }

    &.cherry-toolbar-split {
      font-size: 0;
      height: 50%;
      padding: 0;
      margin-left: 4px;
      margin-right: 4px;
      border: none;
      border-left: 1px solid $toolbarSplitColor;
      pointer-events: none;
      overflow: hidden;
      opacity: 0.5;
    }

    &.disabled {
      color: $toolbarBtnDisabledLight;
    }
  }
}


.cherry {
  .ace_search {
    background: #FFF;
  }
}

.cherry-sidebar {
  width: 30px;
  position: absolute;
  top: 48px;
  right: 7px;
  z-index: 11;
  bottom: 0;
  overflow: hidden;

  .cherry-toolbar-button {
    height: 30px;
    padding: 3px 12px 0 6px;

    &:hover {
      background: transparent;
    }

    .icon-loading {
      &.loading {
        display: inline-block;
        width: 8px;
        height: 8px;
      }

      &.loading:after {
        content: " ";
        display: block;
        width: 8px;
        height: 8px;
        margin-left: 2px;
        margin-top: -2px;
        border-radius: 50%;
        border: 2px solid #000;
        border-color: #000 transparent #000 transparent;
        animation: loading 1.2s linear infinite;
      }
    }

    @keyframes loading {
      0% {
        transform: rotate(0deg);
      }

      100% {
        transform: rotate(360deg);
      }
    }
  }
}

@import './components/bubble';

.cherry-floatmenu {
  z-index: 4;
  display: none;
  position: absolute;
  left: 30px;
  margin-left: 60px;
  height: $lineHeight;
  line-height: $lineHeight;
  border-radius: $borderRadius;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;

  .cherry-toolbar-button {
    float: left;
    padding: 0 9px;
    margin: 0;
    height: $lineHeight;
    line-height: $lineHeight;
    font-size: 14px;
    color: $fontColor;
    overflow: hidden;
    vertical-align: middle;
    text-align: center;
    border: 0;
    cursor: pointer;
    font-style: normal;

    &.cherry-toolbar-split {
      border-left: 1px solid $borderColor;
      width: 0;
      padding: 0;
      overflow: hidden;
      height: 25px;
    }

    .ch-icon {
      color: #aaa;
      font-size: 12px;
    }

    &:hover {
      background: rgba(0, 0, 0, 0.05);

      .ch-icon {
        color: $toolbarBtnColorLight;
      }
    }
  }
}

.cherry-editor {
  position: relative;
  padding-top: 5px;
  padding-right: 5px;
  width: 50%;
  box-sizing: border-box;
  overflow: hidden;

  &.cherry-editor--full {
    width: 100%;
    padding-right: 0;
  }

  &.cherry-editor--hidden {
    display: none;
  }

  &-writing-style {
    &--focus {
      &::before {
        content: '';
        display: block;
        width: 100%;
        position: absolute;
        top: 0;
        background: linear-gradient(to bottom, #00000006, #00000033);
        pointer-events: none;
        z-index: 11;
      }
      &::after {
        content: '';
        display: block;
        width: 100%;
        position: absolute;
        bottom: 0;
        background: linear-gradient(to top, #00000006, #00000033);
        pointer-events: none;
        z-index: 11;
      }
    }
    &--typewriter {
      .CodeMirror-lines {
        position: relative;
        &::before {
          content: '';
          display: block;
        }
        &::after {
          content: '';
          display: block;
        }
      }
    }
  }

  .CodeMirror {
    font-family: $fontFamily;
    background: $editorBg;
    color: $fontColor;

    // codemirror 依赖隐藏的 textarea 计算行高，这里将字体大小设置为行高，避免输入法遮挡内容
    // Fixed https://github.com/Tencent/cherry-markdown/issues/82
    textarea {
      font-size: $lineHeight;
    }
  }

  .CodeMirror-lines {
    padding: 15px 34px;

    // 对draw.io的xml数据，和图片里base64格式的数据限定最大宽度
    .drawio,
    .base64 {
      display: inline-block;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 80px;
      white-space: nowrap;
      vertical-align: bottom;
      color: darkmagenta !important;
      font-size: 12px !important;
    }
  }

  .cm-s-default .cm-header {
    color: $editorHeaderColor;
  }

  .cm-s-default .cm-string {
    color: $editorStringColor;
  }

  .cm-s-default .cm-comment {
    color: $editorCommentColor;
    font-family: $monospaceFont;
    font-size: 0.9em;
  }

  .cm-s-default .cm-whitespace,
  .cm-tab {
    font-family: $monospaceFont;
    font-size: 0.9em;
  }

  .cm-s-default .cm-quote {
    color: $editorQuoteColor;
  }

  .cm-s-default .cm-link {
    color: $editorLinkColor;
  }

  .cm-s-default .cm-url {
    background: $editorUrlBgColor;
    font-family: $monospaceFont;
    font-size: 0.9em;
  }

  .cm-s-default .cm-variable-2 {
    color: $editorV2Color;
  }

  .cm-s-default .cm-variable-3 {
    color: $editorV3Color;
  }

  .cm-s-default .cm-keyword {
    color: $editorKeywordColor;
  }
}

.cherry-drag {
  width: 15px;
  cursor: ew-resize;
  position: absolute;
  z-index: 12;
  background: transparent;

  &.cherry-drag--show {
    width: 5px;
    display: block;
    background: #dfe6ee;
  }

  &.cherry-drag--hidden {
    display: none;
  }
}

.cherry-editor-mask {
  z-index: 10;
  position: absolute;
  display: none;
  background: rgba(0, 0, 0, 0.2);

  &.cherry-editor-mask--show {
    display: block;
  }
}

.cherry-previewer-mask {
  z-index: 10;
  position: absolute;
  display: none;
  background: rgba(0, 0, 0, 0.4);

  &.cherry-previewer-mask--show {
    display: block;
  }
}

.cherry-previewer {
  padding: 20px 45px 20px 20px;
  border-left: 2px solid #ebedee;
  width: 50%;
  box-sizing: border-box;
  background-color: $previewBg;
  min-height: auto;
  overflow-y: auto;

  .cherry-mobile-previewer-content {
    width: 375px;
    height: 100%;
    margin: 0 auto;
    padding: 25px 30px;
    overflow-y: scroll;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
  }

  &.cherry-previewer--hidden {
    width: 0;
    display: none;
  }

  &.cherry-previewer--full {
    width: 100%;
  }

  .cherry-list__upper-roman {
    list-style: upper-roman;
  }

  .cherry-list__lower-greek {
    list-style: lower-greek;
  }

  .cherry-list__cjk-ideographic {
    list-style: cjk-ideographic;
  }

  .cherry-list__circle {
    list-style: circle;
  }

  .cherry-list__square {
    list-style: square;
  }


  div[data-type="codeBlock"]:hover {
    .cherry-copy-code-block {
      display: block !important;
      position: relative;
      width: 25px;
      text-align: center;
      height: 25px;
      border: 1px solid #DDD;
      cursor: pointer;
      float: right;
      right: 10px;
      top: 15px;
      color: #FFF;
      border-radius: 5px;
      margin-left: -27px;
      transition: all 0.3s;
      z-index: 2;
    }

    // 浅色系
    [data-code-block-theme='default'] &,
    [data-code-block-theme='funky'] &,
    [data-code-block-theme='solarized-light'] &,
    [data-code-block-theme='coy'] & {
      .cherry-copy-code-block {
        background-color: #3582fb;
      }
    }

    .cherry-copy-code-block:hover {
      color: #3582fb;
      background-color: #eee;
      border-color: #3582fb;
    }
  }
}

.cherry-color-wrap {
  display: none;
  position: fixed;
  width: auto;
  padding: 5px 10px;
  z-index: 6;
  background: #fff;
  box-shadow: $shadow;

  h3 {
    font-size: 12px;
    margin: 0px;
    font-weight: 400;
  }

  [data-toolbar-theme='dark'] & h3 {
    color: $toolbarBtnColorDark;
  }

  .cherry-color-text {
    float: left;
    width: 128px;
    margin: 0 8px 0 5px;
  }

  .cherry-color-bg {
    float: left;
    width: 128px;
    margin-right: 5px;
  }

  .cherry-color-item {
    float: left;
    width: 14px;
    height: 14px;
    border: 1px solid #fff;
    cursor: pointer;

    &:hover {
      border: 1px solid #000;
    }
  }
}


.Cherry-Math {
  svg {
    max-width: 100%;
  }
}

.cherry-suggester-panel {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  background: #fff;
  // border: 1px solid #ccc;
  border-radius: 2px;
  max-height: 500px;
  box-shadow: 0 2px 8px 1px #00000033;

  .cherry-suggester-panel__item {
    border: none;
    white-space: nowrap;
    min-width: 50px;
    padding: 5px 13px;
    color: #333;
    display: block;
    cursor: pointer;

    &.cherry-suggester-panel__item--selected {
      background-color: #f2f2f5;
      text-decoration: none;
      color: #eb7350;
    }
    & > i {
      display: inline-block;
      transform: translateY(2px);
      margin-right: 8px;
    }
  }

}

.cherry-suggestion {
  background-color: #ebf3ff;
  color: #3582fb;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
}

/** 引入自带的主题 */
@import './themes/default.scss';
@import './themes/dark.scss';
@import './themes/light.scss';
@import './themes/green.scss';
@import './themes/red.scss';
@import './themes/violet.scss';
